package com.ebt.m.proposal_v2.bean.temp;

import android.app.Activity;

import java.util.Stack;

/**
 * @author archer.qi
 *         Created on 2017/5/26.
 */
public class ActivityFinishStack {

    private static ActivityFinishStack INSTANCE;

    public static ActivityFinishStack getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new ActivityFinishStack();
        }
        return INSTANCE;
    }

    public static Stack<Activity> mTempFinishActivityStack;

    public void add(Activity activity) {
        if (activity == null) {
            return;
        }
        if (mTempFinishActivityStack == null) {
            mTempFinishActivityStack = new Stack<>();
        }
        mTempFinishActivityStack.add(activity);
    }

    public void remove(Activity activity) {
        if (activity == null) {
            return;
        }
        if (mTempFinishActivityStack != null && mTempFinishActivityStack.contains(activity)) {
            mTempFinishActivityStack.remove(activity);
        }
    }

    public void finishAllElement() {
        if (mTempFinishActivityStack == null) {
            return;
        }
        for (Activity activity : mTempFinishActivityStack) {
            if (activity != null) {
                activity.finish();
            }
        }
        mTempFinishActivityStack.clear();
    }

    public void clearAllElement() {
        if (mTempFinishActivityStack == null) {
            return;
        }
        mTempFinishActivityStack.clear();
    }


}
